﻿'*******************************************************************************************
'* Copyright Brügmann Software GmbH, Papenburg
'* Author: Björn Kremer
'* Contact: codeplex<at>patorg.de
'* 
'* VB.CMIS is a VB.NET implementation of the Content Management Interoperability Services (CMIS) standard
'*
'* This file is part of VB.CMIS.
'* 
'* VB.CMIS is free software: you can redistribute it and/or modify
'* it under the terms of the GNU Lesser General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'* 
'* VB.CMIS is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU Lesser General Public License for more details.
'* 
'* You should have received a copy of the GNU Lesser General Public License
'* along with VB.CMIS. If not, see <http://www.gnu.org/licenses/>.
'*******************************************************************************************
Imports System
Imports System.Runtime.Serialization
Imports System.Xml.Serialization
Imports System.Xml

Namespace CMISObjects
   <XmlRoot("rendition", Namespace:=CmisNamespaceConstants.Cmis)>
   Public Class Rendition
      Implements IXmlSerializable

      Public Property StreamId() As String

      Public Property MimeType() As String

      Public Property Length() As Long

      Public Property Kind() As String

      Public Property Title() As String

      Public Property Height() As Double

      Public Property Width() As Double

      Public Property RenditionDocumentId() As String

      Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema
         Return Nothing
      End Function

      Public Sub ReadXml(reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml
         Dim doc As New XmlDocument()
         doc.Load(reader)

         Dim node As XmlNode = Common.GetItemCaseInsensitiveFromXML(doc, "rendition")
         For Each child As XmlNode In node.ChildNodes
            Dim lName As String = Common.GetNodeNameWithoutPrefix(child).ToLowerInvariant
            If lName.Equals("streamid") Then
               StreamId = child.InnerText
            ElseIf lName.Equals("mimetype") Then
               MimeType = child.InnerText
            ElseIf lName.Equals("length") Then
               Length = CLng(child.InnerText)
            ElseIf lName.Equals("kind") Then
               Kind = child.InnerText
            ElseIf lName.Equals("title") Then
               Title = child.InnerText
            ElseIf lName.Equals("height") Then
               Height = CDbl(child.InnerText)
            ElseIf lName.Equals("width") Then
               Width = CDbl(child.InnerText)
            ElseIf lName.Equals("renditiondocumentid") Then
               RenditionDocumentId = child.InnerText
            End If
         Next
      End Sub

      Public Sub WriteXml(writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml
         Dim nsCore As String = CmisNamespaceConstants.Cmis
         writer.WriteElementString("streamId", nsCore, StreamId)
         writer.WriteElementString("mimetype", nsCore, MimeType)
         writer.WriteElementString("length", nsCore, CStr(Length))
         writer.WriteElementString("kind", nsCore, Kind)
         writer.WriteElementString("title", nsCore, Title)
         If Height > 0 Then
            writer.WriteElementString("height", nsCore, CStr(Height))
         End If
         If Width > 0 Then
            writer.WriteElementString("width", nsCore, CStr(Width))
         End If
         If Not String.IsNullOrEmpty(RenditionDocumentId) Then
            writer.WriteElementString("renditionDocumentId", nsCore, RenditionDocumentId)
         End If
      End Sub
   End Class
End Namespace